#include <QStringList>
#include "relaytimer.h"

RelayTimer::RelayTimer()
{
    mCId = 0;
    mBId = 0;
    mRId = 0;

    mStartTime = "";
    mStartAction = ACTION_OFF;
    mEndTime = "";
    mEndAction = ACTION_OFF;
    mDayOfWeek = 0;

    uuid = "";

    mStartSunLight = 0;
    mEndSunLight = 0;
}

RelayTimer::RelayTimer(quint8 cid, quint8 bid, quint8 rid, QString& startTime, quint8 startAction, QString& endTime, quint8 endAction, quint8 dayOfWeek)
{
    mCId = cid;
    mBId = bid;
    mRId = rid;

    mStartTime = startTime;
    mStartAction = startAction;
    mEndTime = endTime;
    mEndAction = endAction;
    mDayOfWeek = dayOfWeek;

    uuid = "";

    mStartSunLight = 0;
    mEndSunLight = 0;
}

bool RelayTimer::parseTime(QString time, int *hour, int *minute)
{
    time = time.trimmed();

    QStringList list = time.split(':');
    if (2 == list.count()) {
        int Hour = list.at(0).toInt();
        if ((0 <= Hour) && (24 > Hour)) {
            int Minute = list.at(1).toInt();
            if ((0 <= Minute) && (60 > Minute)) {
                if (hour) {
                    *hour = Hour;
                }
                if (minute) {
                    *minute = Minute;
                }
                return true;
            }
        }
    }

    if (hour) {
        *hour = -1;
    }
    if (minute) {
        *minute = -1;
    }
    return false;
}
